package com.wangzhixuan.commons.utils.excel;

import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import java.io.InputStream;
import java.text.SimpleDateFormat;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import com.wangzhixuan.model.vo.ExcelJobInfomationVo;


public class ExcelForGdtask {

	
	
	public static void excelForGdtask(ExcelJobInfomationVo excelJobInfomationVo) throws IOException {
		// excel模板路径
		String path = "E:\\test1.xls";
		File fi = new File(path);
		InputStream inp = new FileInputStream(fi);
		POIFSFileSystem fs = new POIFSFileSystem(inp);
		// 读取excel模板
		HSSFWorkbook wb = new HSSFWorkbook(fs);
		// 读取了模板内所有sheet内容
		HSSFSheet sheet = wb.getSheetAt(0);
		// 在相应的单元格进行赋值
		HSSFCell cell = sheet.getRow(3).getCell(1);   //3-1 对应的 4-B
		cell.setCellValue(excelJobInfomationVo.getJobName());
		HSSFCell cell2 = sheet.getRow(3).getCell(3);
		cell2.setCellValue(excelJobInfomationVo.getJobDescribe());
		HSSFCell cell3 = sheet.getRow(3).getCell(5);
		cell3.setCellValue(excelJobInfomationVo.getJobCategory());
		
		SimpleDateFormat DatetoString = new SimpleDateFormat();
		HSSFCell cell4 = sheet.getRow(4).getCell(1);   //3-1 对应的 4-B
		cell4.setCellValue(excelJobInfomationVo.getAddress());
		HSSFCell cell5 = sheet.getRow(4).getCell(3);
		cell5.setCellValue(excelJobInfomationVo.getStatus());
		HSSFCell cell6 = sheet.getRow(4).getCell(5);
		cell6.setCellValue(excelJobInfomationVo.getCreatName());
		
		HSSFCell cell7 = sheet.getRow(5).getCell(2);   //3-1 对应的 4-B
		cell7.setCellValue(DatetoString.format((excelJobInfomationVo.getEndTime())));
		HSSFCell cell8 = sheet.getRow(5).getCell(5);
		cell8.setCellValue(excelJobInfomationVo.getCreatPhone());
		
		HSSFCell cell9 = sheet.getRow(6).getCell(2);
		cell9.setCellValue(DatetoString.format(excelJobInfomationVo.getInfaceEndTime()));
		HSSFCell cell10 = sheet.getRow(6).getCell(5);
		cell10.setCellValue(DatetoString.format(excelJobInfomationVo.getStartTime()));
		
		// 修改模板内容导出新模板
		//String outPath = "‪‪‪E:\\test2.xls";
		String outPath = "E:\\test2.xls";
		FileOutputStream out = new FileOutputStream(outPath);
		wb.write(out);
		out.close();
	}

}
